import Koa from 'koa'
import Router from 'koa-router'
import mysql from 'mysql2/promise'
import cors from '@koa/cors'
import bodyParser from 'koa-bodyparser'


const app = new Koa()
const router = new Router()

const pool = mysql.createPool(
    {
        host: 'localhost',
        database: 'Student',
        user: 'root',
        password: '123456'
    }
)
router.get('/', async (ctx) => {
    const [rows] = await pool.query('select * from student')
    ctx.body=rows
})
app.use(cors())
app.use(bodyParser())
app.use(router.routes())
app.listen(8080, () => {
    console.log('http://localhost:8080')
})